<?php

namespace App\Admin\Controllers;

use App\Models\Reports;
use App\Models\Roasts;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Encore\Admin\Widgets\Table;

class RoastController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '吐槽建议';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Roasts);
        $grid->model()->orderBy('id', 'desc');

        $grid->column('id', __('Id'));
        $grid->column('user_id', __('用户 id'));
        $grid->column('user.mobile', __('手机号'));
        $grid->column('roast_txt', __('吐槽描述'));
        $grid->column('praise_txt', __('夸夸描述'));
        $grid->column('status', __('处理装填'));
        $grid->column('mark', __('处理备注'));
        $grid->column('created_at', __('提交时间'));
        $grid->column('updated_at', __('Updated at'));

        $grid->disableCreateButton();
        $grid->disableColumnSelector();

        $grid->actions(function (Grid\Displayers\Actions $actions){
            $actions->disableView();
            $actions->disableDelete();
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Roasts::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('user_id', __('User id'));
        $show->field('roast_txt', __('Roast txt'));
        $show->field('praise_txt', __('Praise txt'));
        $show->field('status', __('Status'));
        $show->field('mark', __('Mark'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Roasts);

        $form->display('user_id', __('用户 id'));
        $form->display('roast_txt', __('吐槽描述'));
        $form->display('praise_txt', __('夸夸描述'));
        // 子表字段


        $form->radio('status', __('处理状态'))->options(Reports::$statusLabels)->default(0);
        $form->textarea('mark', __('处理备注'));
        $form->hasMany('images', function (Form\NestedForm $form){
            $form->file('img_url');

        });
        return $form;
    }
}
